import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AnswerIdCard } from './answerIdCard.entity';


@Injectable()
export class AnswerIdCardService {
  constructor(
    @InjectRepository(AnswerIdCard)
    private catsRepository: Repository<AnswerIdCard>,
  ) {}

  findAll(): Promise<AnswerIdCard[]> {
    return this.catsRepository.find();
  }

  findOne(id: any): Promise<AnswerIdCard> {
    return this.catsRepository.findOne(id);
  }

  async get_id_card(wx_user: string,video_id: number){
    let findIdCard = await this.catsRepository.query(`
      select id_card from answer_id_card
      where wx_user = ? and video_id = ?
    `,[wx_user, video_id])
    if(findIdCard.length > 0){
      return findIdCard[0].id_card
    }else{
      return 1
    }
  }

  async remove(id: number): Promise<void> {
    await this.catsRepository.delete(id);
  }

  async create(cats: AnswerIdCard): Promise<void> {
    await this.catsRepository.save(cats);
  }
}
